package com.bw.base.mvvm

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bw.base.entity.Res
import kotlinx.coroutines.launch

open class BaseViewModel:ViewModel() {
    fun<T> httpRequest(s:suspend  ( )-> Res<T>, success:(T)->Unit){
        try {
                viewModelScope.launch {
                    val res = s.invoke()
                    if (res.code == 200){
                        success(res.data)
                    } else {
                        Log.i("===",res.msg)
                    }
                }
        } catch (e: Exception) {
           Log.i("===",e.message.toString())
        }
    }
}